/*
 * clipboard.cpp
 *
 *  Created on: 04/gen/2013
 *      Author: Administrator
 */

#include <windows.h>
#include <iostream>

#include "clipboard.h"

using namespace std;

//uso
//readclipboard();
string readclipboard(){
  OpenClipboard(NULL);
        HANDLE foo = GetClipboardData(CF_TEXT);
        CloseClipboard();
        LPVOID lptstr = GlobalLock(foo);
        return (char *)lptstr;
}

//uso
//writeclipboard("ciao");
int writeclipboard(char *text){
  HGLOBAL hText;
          char *pText;
          hText = GlobalAlloc(GMEM_DDESHARE|GMEM_MOVEABLE, 100);
          pText = (char*)GlobalLock(hText);
          strcpy(pText, text);
          GlobalUnlock(hText);

          OpenClipboard(NULL);
          EmptyClipboard();
          SetClipboardData(CF_TEXT, hText);
          CloseClipboard();
}

